﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Net;
using System.Text;
using System.Windows.Forms;


namespace SalesTracker.Tools.EntityComparer
{
    public partial class login : UserControl
    {
        public EnitityComparerMain MainForm { get; set; }


        public login()
        {
            InitializeComponent();
           
        }
       

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnlogin_Click(object sender, EventArgs e)
        {
            validateinput();
           
        }

        /// <summary>
        /// 
        /// </summary>
        void validateinput()
        {
           
            
            if (txtUserName.Text.Length == 0 || txtPassword.Text.Length == 0 || txtDomain.Text.Length == 0)
            {
                txtUrl.BackColor = Color.Red;
                txtUrl.ForeColor = Color.White;
                return;
            }
            txtUrl.BackColor = Color.Green;
            txtUrl.ForeColor = Color.White;
            SecondForm.Visible = false; 
            var credentials = new NetworkCredential(txtUserName.Text, txtPassword.Text, txtDomain.Text);

            if (txtUrl.Name == "txtLatestCrmUrl")
            {
                MainForm.PrimaryUrlCredentials = credentials;
                return;
            }

            if (txtUrl.Name == "txtOutdatedCrmEnvironmentUrl")
            {
                MainForm.SecondaryUrlCredentials = credentials;
                return;
            }
           
        }

        public LoginForm SecondForm { get; set; }

        public TextBox txtUrl { get; set; }
    }
}
